home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / library / ix_close.c < prev    next >
C/C++ Source or Header  |  1995-12-23  |  4KB  |  120 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  ix_close.c,v 1.1.1.1 1994/04/04 04:30:26 amiga Exp
  20.  *
  21.  *  ix_close.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:26  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.7  1993/11/05  21:53:38  mw
  26.  *  close inet-library, if we opened it
  27.  *
  28.  *  Revision 1.6  1992/10/20  16:18:58  mwild
  29.  *  moved closing of files out before Forbid (ix_startup, vfork)
  30.  *  possibly free a4 databss-segment here (see ix_resident.c)
  31.  *
  32.  *  Revision 1.5  1992/08/09  20:46:42  amiga
  33.  *  delay restoring of old handlers
  34.  *
  35.  *  Revision 1.4  1992/07/04  19:12:12  mwild
  36.  *  don't just free death-messages, wake any children possibly waiting on them
  37.  *
  38.  * Revision 1.3  1992/05/22  01:44:17  mwild
  39.  * when debugging, check whether buddy allocator clean
  40.  *
  41.  * Revision 1.2  1992/05/18  12:18:00  mwild
  42.  * changed async mp to be global
  43.  *
  44.  * Revision 1.1  1992/05/14  19:55:40  mwild
  45.  * Initial revision
  46.  *
  47.  */
  48.  
  49. #define KERNEL
  50. #include "ixemul.h"
  51. #include "kprintf.h"
  52. #include <hardware/intbits.h>
  53.  
  54. extern struct ExecBase     *SysBase;
  55.  
  56. void
  57. ix_close (struct ixemul_base *ixbase)
  58. {
  59.   struct Task         *me      =    SysBase->ThisTask;
  60.   struct user         *ix_u     =    (struct user *) me->tc_TrapData;
  61.   struct Process    *child;
  62.   struct user        *cu;
  63.   struct Node        *dm, *ndm;    /* really struct death_msg * */
  64.  
  65.   RemIntServer (INTB_VERTB, &ix_u->u_itimerint);
  66.   /* already reset the trap vector here. It's better to get an alert than
  67.    * to loop infinitely if one of the following functions should crash */
  68.   me->tc_TrapCode = ix_u->u_otrap_code;
  69.  
  70.   /* had to move this block after the SYS_close's, since close() might have
  71.      to wait for a packet, and then it's essential that our switch/launch
  72.      handlers are still active */
  73.   me->tc_Flags    = ix_u->u_otask_flags;
  74.   me->tc_Launch      = ix_u->u_olaunch;
  75.   me->tc_Switch   = ix_u->u_oswitch;
  76.   FreeSignal (ix_u->u_sleep_sig);
  77.   if (ix_u->u_InetBase)
  78.     {
  79.       FreeSignal (ix_u->u_sigurg);
  80.       FreeSignal (ix_u->u_sigio);
  81.       CloseLibrary (ix_u->u_InetBase);
  82.     }
  83.   CloseDevice ((struct IORequest *) ix_u->u_time_req);
  84.   syscall (SYS_DeleteExtIO, ix_u->u_time_req);
  85.   
  86.   if (ix_u->u_startup_cd != (BPTR) -1) __unlock (CurrentDir (ix_u->u_startup_cd));
  87.  
  88.   ix_u->u_trace_flags = 1;
  89.   DeletePort (ix_u->u_sync_mp);
  90.  
  91.   for ((child = ix_u->p_cptr); child; (child = cu->p_osptr))
  92.     {
  93.       cu = (struct user *)child->pr_Task.tc_TrapData;
  94.       cu->p_pptr = (struct Process *) 1;
  95.     }
  96.  
  97.   ix_u->p_cptr = 0;
  98.   
  99.   for (dm  = (struct Node *) ix_u->p_zombies.mlh_Head;
  100.        (ndm = dm->ln_Succ);
  101.        dm  = ndm)
  102.     {
  103.       /* there might be children sleeping on this, so wake them up now.. */
  104.       ix_wakeup ((u_int)dm);
  105.       kfree (dm);
  106.     }
  107.  
  108.   FreeSignal (ix_u->p_zombie_sig);
  109.  
  110.   all_free ();
  111.   if (ix_u->p_flag & SFREEA4)
  112.     kfree ((void *)(ix_u->u_a4 - 0x7ffe));
  113.  
  114.   /* delay this until here, since the above called functions need access
  115.    * to the user area. */
  116.   me->tc_TrapData = ix_u->u_otrap_data;
  117.  
  118.   kfree (ix_u);
  119. }
  120.